package com.shenmazong.serverboottest.mapper;

import com.shenmazong.serverboottest.pojo.TbUser;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

/**
 * @author 田不平
 * @project server-security
 * @date 2020/3/8 4:54 PM
 * http://www.shenmazong.com
 */

@Mapper
@Component(value = "iDbMapper")
public interface IDbMapper {

    // select
    @Select("SELECT * FROM tb_user WHERE id = #{id}")
    TbUser getUserById(@Param("id") Integer id);

    // insert
    @Insert("INSERT INTO tb_user(UserName,Age) VALUES(#{UserName},#{Age})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    int addUser(TbUser user);

    // delete
    void delUser(@Param("userId") Integer userId);

    // update
    @Update("UPDATE tb_user\n" +
            "SET UserName=#{UserName},Age=#{Age}\n" +
            "WHERE id=#{id}")
    void updateUser(TbUser user);
}
